package com.pokeoffice.commands;

import java.sql.Connection;
import java.sql.SQLException;

import com.pokeoffice.builder.UserBuilder;
import com.pokeoffice.database.Control;
import com.pokeoffice.interfaces.Command;
import com.pokeoffice.users.User;

/**
 * The Class CreateUserCommand.
 */
public class CreateUserCommand implements Command {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -8615848138800149668L;
	
	/** The s. */
	private String[] s;
	
	/**
	 * Instantiates a new creates the user command.
	 *
	 * @param s the s
	 */
	public CreateUserCommand(String[] s) {
		this.s = s;
	}
	
	/* (non-Javadoc)
	 * @see com.pokeoffice.interfaces.Command#execute()
	 */
	public void execute() {
		User use = UserBuilder.buildFromStringArray(s);
		Control ctrl = Control.get();
		
		try {
			ctrl.createUser(root(), use);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Root.
	 *
	 * @return the connection
	 */
	public Connection root() {
		return Control.get().connect("root", "root");
	}

}
